package com.example.hudongwx.myclass0719application.fragment;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.example.hudongwx.myclass0719application.R;
import com.example.hudongwx.myclass0719application.UserActivity;

import org.xutils.view.annotation.ContentView;
import org.xutils.view.annotation.ViewInject;
import org.xutils.x;

/**
 *
 * 点击聚赞先跳刀这里
 * Created by hudongwx on 16-10-29.
 */

  @ContentView(R.layout.fragjuzan1)
public class FragJuZan1 extends Fragment{
    @ViewInject(R.id.fragjuzan1_tablyout)
    private TabLayout tabLayout;
    @ViewInject(R.id.fragjuzan1_viewpager)
    private ViewPager viewPager;
    private View view;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
             if (view==null){
           view= x.view().inject(this,inflater,container);
           //绑定关系
                 viewPager.setAdapter(new Myadpater(getActivity().getSupportFragmentManager()));
                 tabLayout.setupWithViewPager(viewPager);
                 viewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
                     @Override
                     public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

                     }

                     @Override
                     public void onPageSelected(int position) {
                         if (position==1){
                             //先直接跳转登陆
                             startActivity(new Intent(getActivity(), UserActivity.class));
                         }
                     }

                     @Override
                     public void onPageScrollStateChanged(int state) {

                     }
                 });
             }
        return view;
    }

    //适配器
    class  Myadpater extends FragmentPagerAdapter{


        public Myadpater(FragmentManager fm) {
            super(fm);
        }

        @Override
        public Fragment getItem(int position) {

            if (position==0){
                return new FragJuZan();
            }else {
                return  new FragJuZan2();
            }

        }

        @Override
        public int getCount() {
            return 2;
        }

        @Override
        public CharSequence getPageTitle(int position) {
          if (position==0){
              return "聚赞";
          }else {
              return "我的聚赞";
          }
        }
    }
}
